package com.gzx.plugin.tjzy.modular.excel.template.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.plugin.tjzy.modular.excel.template.bo.GzxExcelTemplateAddBo;
import com.gzx.plugin.tjzy.modular.excel.template.bo.GzxExcelTemplateQueryBo;
import com.gzx.plugin.tjzy.modular.excel.template.service.GzxExcelTemplateService;
import com.gzx.plugin.tjzy.modular.excel.template.vo.GzxExcelTemplateVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.common.pojo.CommonResult;

import java.io.IOException;
import java.util.List;

/**
 * @author zjt
 * @description
 * @date 2025/5/9 17:29
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/tjzy/excel/template")
public class GzxExcelTemplateController {


    private final GzxExcelTemplateService excelTemplateService;

    @PostMapping("/pageList")
    public CommonResult<Page<GzxExcelTemplateVo>> pageList(@RequestBody GzxExcelTemplateQueryBo excelTemplateQueryBo) {
        return CommonResult.data(excelTemplateService.pageList(excelTemplateQueryBo));
    }

    @GetMapping("/getTemplateListByType/{type}")
    public CommonResult<List<GzxExcelTemplateVo>> getTemplateListByType(@PathVariable Integer type) {
        return CommonResult.data(excelTemplateService.getTemplateListByType(type));
    }

    @PostMapping("/upload")
    public CommonResult<Void> upload(@RequestPart("excelTemplateAddBo") GzxExcelTemplateAddBo excelTemplateAddBo, @RequestPart("multipartFile") MultipartFile multipartFile) throws IOException {
        excelTemplateService.upload(excelTemplateAddBo, multipartFile);
        return CommonResult.ok();
    }

    @GetMapping("/del/{id}")
    public CommonResult<Void> del(@PathVariable Long id) {
        excelTemplateService.del(id);
        return CommonResult.ok();
    }
}
